<?php
// +----------------------------------------------------------------------
// | xiongrui [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.xiongrui.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.xiongrui.cn>
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\controller\Admin;

class Message extends Admin {

	public function _initialize() {
		parent::_initialize();
	}

	public function index() {
    $map = '';
    $list  = model("message")->where($map)->field(true)->order('id desc')->paginate(20);

    $this->setMeta('会员留言');
		$this->assign('list', $list);
		return $this->fetch();
	}

	public function edit($id) {
		if (!$id) {
			return $this->error("非法操作！");
		}
		if (IS_POST) {

			$map['message_id'] = $id;

			$info = model('messageReply')->where($map)->find();


			$data['content'] = input('post.content');
			$data['message_id'] = $id;
			$data['admin_id'] =  session('user_auth.uid');

			if($info){
				$result = model('messageReply')->save($data, ['id'=>$info['id']]);
			}else{
				$result = model('messageReply')->save($data);
			}



		//	$result =  model('messageReply')->change();
			if ($result) {
				return $this->success("编辑成功！", url('admin/message/index'));
			} else {
				return $this->error("编辑失败！");
			}
		} else {
			$info = model('message')->where(array('id' => $id))->find();

			$this->assign('info', $info);
			$this->setMeta('查看留言');
			return $this->fetch();
		}
	}

}
